package com.example.resourceSharingPlatform.dao;

import com.example.resourceSharingPlatform.entity.CDKey;
import com.example.resourceSharingPlatform.mappers.CDKeyRowMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

@Service
public class CDKeyDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public CDKey queryCDKeyByKey(String key){
        String sql = "SELECT * FROM cdkey WHERE cdk=?";
        return jdbcTemplate.queryForObject(sql, new CDKeyRowMapper(), key);
    }

    public boolean updateCDKeyByKey(String key,String used){
        String sql = "UPDATE cdkey SET used=? WHERE cdk=?";
        int row = jdbcTemplate.update(sql, used, key);
        return row !=0;
    }
}
